#include "StdAfx.h"
#include "SailConfig.h"


using namespace System;
using namespace Runtime::InteropServices;

namespace ManagedSail 
{
	/*

	SailConfig::SailConfig() : rank(0), resX(0), resY(0), pixFmt(format888), 
			rowOrd(TopToBottom), nwID(1), fsPort(0), syncPort(0), msgPort(0), appID(0), 
			master(true), rendering(true), winX(100), winY(100), winWidth(500), winHeight(500),
			protocol(NetworkProtocol::TCP), rcvBufSize(0), syncMode(0), asyncUpdate(true), blockSize(0),
			bufWarnLimit(5), bufIncRatio(10), maxBlockLoss(10), ackInterval(50),  totalFrames(0),
			senderCheckInterval(10), minSendRate(100), maxSendRate(900), compression(NoCompression),
			bridgeOn(false), bridgePort(0) , audioOn(false), audioPort(0), audioDeviceNum(0),
					sampleFmt(Float32), samplingRate(44100), channels(2), framePerBuffer(1024),
					syncType(None)
	{
		appName = "";
		masterIP = "";
		fsIP = "";
		bridgeIP = "";	
	}

	void SailConfig::SetApplicationName(String^ applicationName)
	{
		appName = applicationName;
	}

	void SailConfig::Init(String^ fname)
	{		
		::sailConfig* config = new ::sailConfig();
		char* chars = (char*)(Marshal::StringToHGlobalAnsi(fname)).ToPointer();

		if(config->init(chars) != 0)
			throw gcnew Exception("Couldn't load initialization data from " + fname);

		appName = gcnew String(config->appName);
		masterIP = gcnew String(config->masterIP);
		fsIP = gcnew String(config->fsIP);
		bridgeIP = gcnew String(config->bridgeIP);
		audioFileName = gcnew String(config->audioFileName);
		streamIP = gcnew String(config->streamIP);

		nwID = config->nwID;
		fsPort = config->fsPort;
		bridgePort = config->bridgePort;
		bridgeOn = config->bridgeOn;
		syncPort = config->syncPort;
		msgPort = config->msgPort;
		nodeNum = config->nodeNum;
		appID = config->appID;
		blockX = config->blockX;
		blockY = config->blockY;
		blockSize = config->blockSize;
		winX = config->winX;
		winY = config->winY;
		winWidth = config->winWidth;
		winHeight = config->winHeight;
		protocol = (NetworkProtocol)config->protocol;
		syncMode = config->syncMode;
		streamMode = config->streamMode;
		rcvBufSize = config->rcvBufSize;
		rank = config->rank;
		resX = config->resX;
		resY = config->resY;		
		pixFmt = (PixelFormat)config->pixFmt;
		rowOrd = (RowOrder)config->rowOrd;
		master = config->master;
		rendering = config->rendering;
		asyncUpdate = config->asyncUpdate;
		compression = (CompressionType)config->compression;
		totalFrames = config->totalFrames;
		audioOn = config->audioOn;
		audioMode = (AudioMode)config->audioMode;
		audioPort = config->audioPort;
		audioDeviceNum = config->audioDeviceNum;
		sampleFmt = (SampleFormat)config->sampleFmt;
		samplingRate = config->samplingRate;
		channels = config->channels;
		framePerBuffer = config->framePerBuffer;
		syncType = (SyncType)config->syncType;
		audioBuffSize = config->audioBuffSize;
		frameRate = config->frameRate;
		bufIncRatio = config->bufIncRatio;
		maxBlockLoss = config->maxBlockLoss;
		ackInterval = config->ackInterval;
		senderCheckInterval = config->senderCheckInterval;
		minSendRate = config->minSendRate;
		maxSendRate = config->maxSendRate;

		if(config->imageMap.width == 0)
			imageMap = gcnew SageRectangle(config->imageMap.left, config->imageMap.right, config->imageMap.bottom, config->imageMap.top);
		else
			imageMap = gcnew SageRectangle(config->imageMap.x, config->imageMap.y, config->imageMap.width, config->imageMap.height);

		delete config;
	}
*/
}